package com.dxd.onlineshop.controller;

import com.dxd.onlineshop.pojo.Notification;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;

@CrossOrigin
@Controller
public class WebSocketController {

    //接受app/notification的客户端消息
    @MessageMapping("/notification")
    //转发通知给订阅topic/notifications的客户端
    @SendTo("/topic/notifications")
    public Notification sendNotification(Notification notification) {
        return notification;
    }
}